class Storage {
  constructor (id, coverPic, compositeScore, looks, address, distance, href) {
    this.id = id
    this.cover_pic = coverPic
    this.composite_score = compositeScore
    this.looks = looks
    this.address = address
    this.distance = distance
    this.href = href
  }
}
/**
 *
 * @param {id} id
 * @param {coverPic} 图片
 * @param {compositeScore} 星级
 * @param {looks} 点击
 * @param {address} 地址
 * @param {distance} 距离
 */
function storageHistory (
  id,
  coverPic,
  compositeScore,
  looks,
  address,
  distance,
  href
) {
  let storage = new Storage(
    id,
    coverPic,
    compositeScore,
    looks,
    address,
    distance,
    href
  )
  return storage
}
/**
 *
 * @param {array} 去重
 */
export function uniq (array) {
  const hash = {}
  if (!Array.isArray(array)) {
  }
  array = array.reduce((item, next) => {
    if (!hash[next.id]) {
      hash[next.id] = true && item.push(next)
    }
    return item
  }, [])
  return array
}

export function storageType (
  type,
  id,
  coverPic,
  compositeScore,
  looks,
  address,
  distance,
  href
) {
  let history = storageHistory(
    id,
    coverPic,
    compositeScore,
    looks,
    address,
    distance,
    href
  )
  let typeHistory = JSON.parse(this.$localStorage.get(type))
  if (typeHistory != null) {
    typeHistory.push(history)
    this.$localStorage.set(type, JSON.stringify(uniq(typeHistory)))
  } else {
    const browse = []
    browse.push(history)
    this.$localStorage.set(type, JSON.stringify(browse))
  }
}
